package com.tobeface.wechat.message.builder;

import com.google.common.collect.Maps;
import com.tobeface.modules.lang.Requires;
import com.tobeface.wechat.message.WeChatMessage;
import com.tobeface.wechat.message.WeChatMessageBuilder;
import com.tobeface.wechat.message.TypedWeChatMessageBuilder;

import java.util.Map;

/**
 * @author loudyn
 */
public abstract class AbstractTypedMessageBuilder implements TypedWeChatMessageBuilder {
    private final WeChatMessageBuilder parent;
    private final Map<String, Object> payloads = Maps.newHashMap();

    /**
     * @param parent
     */
    public AbstractTypedMessageBuilder(WeChatMessageBuilder parent) {
        Requires.notNull(parent, "parent must not be null!");
        this.parent = parent;
    }

    @Override
    public WeChatMessage build() {
        configPayloads(payloads);
        return parent.payloads(payloads).build();
    }

    /**
     * @param payloads
     */
    protected abstract void configPayloads(Map<String, Object> payloads);
}
